package cn.stylefeng.guns.sys.modular.system.controller;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum;
import cn.stylefeng.guns.sys.modular.system.entity.*;
import cn.stylefeng.guns.sys.modular.system.model.params.CheciParam;
import cn.stylefeng.guns.sys.modular.system.service.BtyWlYfmxService;
import cn.stylefeng.guns.sys.modular.system.warpper.NoticeWrapper;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 运费明细控制器
 * @author
 * @Date 2020-1-4
 */
@Controller
@RequestMapping("/yfmx")
public class BtyWlYfmxController extends BaseController {

    private String PREFIX = "/modular/system/btyYfmx/";

    @Resource
    private BtyWlYfmxService yfmxService;


    /**
     * 跳转到运费明细列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "yfmx.html";
    }

    /**
     * 跳转到添加运费明细
     */
    @RequestMapping("/checi_add")
    public String noticeAdd() {
        return PREFIX + "checi_add.html";
    }

    /**
     * 跳转到修改运费明细
     */
    @RequestMapping("/checi_update")
    public String noticeUpdate() {
        return PREFIX + "checi_edit.html";
    }

    /**
     * 获取运费明细列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(CheciParam checiParam) {
        Page<Map<String, Object>> list = this.yfmxService.list(checiParam);
        Page<Map<String, Object>> wrap = new NoticeWrapper(list).wrap();
        return LayuiPageFactory.createPageInfo(wrap);
    }
    /**
     * 获取运费明细导出excel列表
     */
    @RequestMapping(value = "/listExport")
    @ResponseBody
    public Object listExport(CheciParam checiParam) {
        List<Map<String, Object>> list = this.yfmxService.listExport(checiParam);
        return list;
    }

    /**
     * 删除运费明细
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long id) {
        this.yfmxService.removeById(id);
        return SUCCESS_TIP;
    }

    /**
     * 修改运费明细
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(BtyWlYfmx yfmx) {
        if (ToolUtil.isOneEmpty(yfmx, yfmx.getId())) {
            throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
        }
        yfmx.setCreateTime(null);
        if(ToolUtil.isNotEmpty(yfmx.getGz())){
            yfmx.setGz(yfmx.getGz());
        }
        this.yfmxService.updateById(yfmx);
        return SUCCESS_TIP;
    }

    /**
     * 运费明细详情
     */
    @RequestMapping("/info")
    @ResponseBody
    public Object getThemeInfo(@RequestParam String id) {
        if (ToolUtil.isEmpty(id)) {
            throw new RequestEmptyException();
        }
        return this.yfmxService.getById(id);
    }

    /**
     *查找历史路线
     */
    @RequestMapping(value = "/getPslx")
    @ResponseBody
    public Object getPslxByDm(CheciParam checiParam) {
        Page<Map<String, Object>> areaList=yfmxService.getPslxByDm(checiParam);
        Page<Map<String, Object>> wrap = new NoticeWrapper(areaList).wrap();
        return LayuiPageFactory.createPageInfo(wrap);
    }




}
